package com.pioneer.gui.invoice.model;

import javax.swing.*;          //This is the final package name.
//import com.sun.java.swing.*; //Used by JDK 1.2 Beta 4 and all
import javax.swing.event.*;                               //Swing releases before Swing 1.1 Beta 3.							   
import javax.swing.plaf.metal.*;

import com.pioneer.gui.invoice.util.ConnectionServer;
import com.pioneer.gui.invoice.model.DropDownValue;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;

import java.awt.*;
import java.awt.event.*;
import java.util.Vector;

public class SalesmanList
implements ComboBoxModel
{
	private InvoiceModel _model;	
	private Vector _salesmanlist=new Vector();
	private Object[] _dropDownValue;	
	private Connection _conn;
	
	public SalesmanList()
	{
		//this._model=model;		
		Statement stat=null;
		ResultSet rs=null;
		
		ConnectionServer connServer=ConnectionServer.getSingleton();
		try
		{
			_conn=connServer.getConnection();
			stat=_conn.createStatement();
			rs=stat.executeQuery("select * from a01_salesman");
			Object [] dropDownValue;			
			while (rs.next())
			{
				dropDownValue=new Object[2];
				dropDownValue[0]=new Integer(rs.getInt("a01_sman_id"));
				dropDownValue[1]=rs.getString("a01_name");
				this._salesmanlist.add(dropDownValue);
				//this._salesmanlist.add(new DropDownValue(rs.getInt("a01_sman_id"),rs.getString("a01_name")));
			}
		}
		catch (SQLException e)
		{
			System.out.println(e.toString());
		}
		finally
		{
			try
			{
				if (rs!=null) rs.close();
				if (stat!=null) stat.close();
			}
			catch (SQLException e)
			{
				System.out.println(e.toString());
			}
		}
	}		
	
	public Object getSelectedItem() 
	{
		return this._dropDownValue;		
	}
	
	public void setSelectedItem(Object selected) 
	{
		this._dropDownValue=(Object[])selected;		
	}
	
	public void removeListDataListener(ListDataListener l)
	{
	}
	
	public void addListDataListener(ListDataListener l)
	{
	}
	
	public Object getElementAt(int index)
	{		
		return (Object[])_salesmanlist.elementAt(index);		
	}
	
	public int getSize()
	{
		return _salesmanlist.size();
	}	
	
}
	